home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE09
/
CLINIC
/
NEWCTRLS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-03-15
|
3KB
|
104 lines
{ The OnDriveError event allows you to recover from }
{ the situation when you go to a drive and its not ready }
{ To recover from the secondary problem, where you have }
{ successfully gone to drive A:, the floppy is removed }
{ and in attempting to go to another drive, an exception }
{ occurs, you must modify the VCL. In FILECTRL.PAS, locate }
{ TFileListBox.SetDirectory and also }
{ TDirectoryListBox.SetDir and change: }
(* ChDir(FDirectory); *)
{ to be: }
(* {$I-} { ignore errors } *)
(* ChDir(FDirectory); *)
(* {$I+} *)
(* if IOResult = 0 then; *)
{ In Delphi 2, the change has already been made for }
{ TDirectoryListBox.SetDir }
unit Newctrls;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, FileCtrl;
type
TDriveErrorEvent = procedure (Sender: TObject; var Retry: Boolean) of object;
TNewDriveCombo = class(TDriveComboBox)
private
FOnDriveError: TDriveErrorEvent;
protected
procedure Click; override;
published
property OnDriveError: TDriveErrorEvent read FOnDriveError write FOnDriveError;
end;
procedure Register;
implementation
procedure TNewDriveCombo.Click;
var
OldDrive, NewDrive: Char;
Ouch, Retry: Boolean;
begin
OldDrive := Drive;
if Items.Count > 0 then
NewDrive := Items[ItemIndex][1];
Ouch := False;
{ If there's a problem (empty floppy for example) }
{ stop any exception message being printed }
try
inherited Click;
except
on E: EInOutError do
{$ifdef Windows}
{ DOS gives error 3 (Path not found) if }
{ drive not ready on a directory change }
if E.ErrorCode = 3 then
{$else}
{ Win32 gives error 21 (Device not ready) if drive not ready }
{ This is more precise - there is an equivalent error 3 defined }
{ For a list of Win32 errors, (albeit with missing characters) look up }
{ "error codes", "Error Codes (Win32 Programmer's Reference)" }
if E.ErrorCode = ERROR_NOT_READY then
{$endif}
{ Signal to later code that a problem occurred }
Ouch := True;
end;
if Ouch then
repeat
try
{ Set back decent drive first }
Drive := OldDrive;
{ Then check for a retry }
Retry := False;
if Assigned(FonDriveError) then
FOnDriveError(Self, Retry);
if Retry then
{ Try setting target drive again }
Drive := NewDrive;
{ If no exception occurs, we're done so set loop terminator }
Ouch := False;
except
{ Mask the potential problem }
on E: EInOutError do
if E.ErrorCode = 3 then;
end;
until not (Ouch and Retry);
end;
procedure Register;
begin
RegisterComponents('Samples', [TNewDriveCombo]);
end;
end.